source sim_coverage
source sim_mode
puts $env(SIM_MODE)
puts $env(SIM_COVERAGE)
set cdr [pwd]
set DES_PATH   "$cdr/.."
set TB_PATH    "$cdr/."
set LIB_PATH   "$cdr/../../.."
set INC_PATH   "$DES_PATH"
set TINC_PATH  "$TB_PATH/src"
set IP_PATH    "$LIB_PATH/common/quartus_ip"
set TEST_LIB   "$LIB_PATH/common/includes"
set UTILS_PATH "$LIB_PATH/utils"

set QUARTUS $::env(QUARTUS_ROOTDIR)
set QUARTUS [file normalize $QUARTUS]

puts "tcl shortcuts"
puts "do compile.tcl (re-load compile.tcl)"
puts "dcom           (re-compile libraries)"
puts "com_rtl        (re-compile rtl)"
puts "r_rtl          (re-run simulation)"

alias dcom {

transcript on
if ![file isdirectory verilog_libs] {
    file mkdir verilog_libs
}

vlib verilog_libs/altera_ver
vmap altera_ver ./verilog_libs/altera_ver
vlog -vlog01compat -work altera_ver $QUARTUS/eda/sim_lib/altera_primitives.v

vlib verilog_libs/lpm_ver
vmap lpm_ver ./verilog_libs/lpm_ver
vlog -vlog01compat -work lpm_ver $QUARTUS/eda/sim_lib/220model.v

vlib verilog_libs/sgate_ver
vmap sgate_ver ./verilog_libs/sgate_ver
vlog -vlog01compat -work sgate_ver $QUARTUS/eda/sim_lib/sgate.v

vlib verilog_libs/altera_mf_ver
vmap altera_mf_ver ./verilog_libs/altera_mf_ver
vlog -vlog01compat -work altera_mf_ver $QUARTUS/eda/sim_lib/altera_mf.v

vlib verilog_libs/altera_lnsim_ver
vmap altera_lnsim_ver ./verilog_libs/altera_lnsim_ver
vlog -sv -work altera_lnsim_ver $QUARTUS/eda/sim_lib/altera_lnsim.sv

vlib verilog_libs/fiftyfivenm_ver
vmap fiftyfivenm_ver ./verilog_libs/fiftyfivenm_ver
vlog -vlog01compat -work fiftyfivenm_ver $QUARTUS/eda/sim_lib/fiftyfivenm_atoms.v
vlog -vlog01compat -work fiftyfivenm_ver $QUARTUS/eda/sim_lib/mentor/fiftyfivenm_atoms_ncrypt.v
vlog -vlog01compat -work fiftyfivenm_ver $QUARTUS/eda/sim_lib/mentor/cyclonev_atoms_for_vhdl.v
vlog -vlog01compat -work fiftyfivenm_ver $QUARTUS/eda/sim_lib/mentor/cyclonev_atoms_ncrypt.v

if {[file exists rtl_work]} {
    vdel -lib rtl_work -all
}
vlib rtl_work 
vmap work rtl_work


}



alias com_rtl {

transcript on

if {$env(SIM_MODE) == "long"} {
    set SIMULATION_MODE "LONG"
} else {
    set SIMULATION_MODE "SHORT"
}

if {$env(SIM_COVERAGE) == "cov_en"} {
    set SIMULATION_COVERAGE "-coveropt 3 +cover"
} else {
    set SIMULATION_COVERAGE ""
}

if {[file exists rtl_work]} {
    vdel -lib rtl_work -all
}
vlib rtl_work
vmap work rtl_work
eval vlog $SIMULATION_COVERAGE +acc -sv -work rtl_work +incdir+$INC_PATH $DES_PATH/espi_fifo.sv
eval vlog $SIMULATION_COVERAGE +acc -sv -work rtl_work +incdir+$INC_PATH $DES_PATH/espi_cmd_det.sv
eval vlog $SIMULATION_COVERAGE +acc -sv -work rtl_work +incdir+$INC_PATH $DES_PATH/espi_condt_det.sv
eval vlog $SIMULATION_COVERAGE +acc -sv -work rtl_work +incdir+$INC_PATH $DES_PATH/espi_crc_gen.sv
eval vlog $SIMULATION_COVERAGE +acc -sv -work rtl_work +incdir+$INC_PATH $DES_PATH/espi_pc_mem_short_fsm.sv
eval vlog $SIMULATION_COVERAGE +acc -sv -work rtl_work +incdir+$INC_PATH $DES_PATH/espi_pc_io_short_fsm.sv
eval vlog $SIMULATION_COVERAGE +acc -sv -work rtl_work +incdir+$INC_PATH $DES_PATH/espi_pc_short_completion_fsm.sv
eval vlog $SIMULATION_COVERAGE +acc -sv -work rtl_work +incdir+$INC_PATH $DES_PATH/espi_pc_put_pc_fsm.sv
eval vlog $SIMULATION_COVERAGE +acc -sv -work rtl_work +incdir+$INC_PATH $DES_PATH/espi_pc_put_np_fsm.sv
eval vlog $SIMULATION_COVERAGE +acc -sv -work rtl_work +incdir+$INC_PATH $DES_PATH/espi_pc_channel.sv
eval vlog $SIMULATION_COVERAGE +acc -sv -work rtl_work +incdir+$INC_PATH $DES_PATH/espi_oob_channel.sv
eval vlog $SIMULATION_COVERAGE +acc -sv -work rtl_work +incdir+$INC_PATH $DES_PATH/espi_register.sv
eval vlog $SIMULATION_COVERAGE +acc -sv -work rtl_work +incdir+$INC_PATH $DES_PATH/espi_resp_gen.sv
eval vlog $SIMULATION_COVERAGE +acc -sv -work rtl_work +incdir+$INC_PATH $DES_PATH/espi_rx_shifter.sv
eval vlog $SIMULATION_COVERAGE +acc -sv -work rtl_work +incdir+$INC_PATH $DES_PATH/espi_tx_shifter.sv
eval vlog $SIMULATION_COVERAGE +acc -sv -work rtl_work +incdir+$INC_PATH $DES_PATH/espi_vw_gpi_update.sv
eval vlog $SIMULATION_COVERAGE +acc -sv -work rtl_work +incdir+$INC_PATH $DES_PATH/espi_vw_channel.sv
eval vlog $SIMULATION_COVERAGE +acc -sv -work rtl_work +incdir+$INC_PATH $DES_PATH/espi_slave.sv
eval vlog +acc -sv -work rtl_work +incdir+$INC_PATH +incdir+$TINC_PATH $TB_PATH/src/espi_pkg.sv
eval vlog +acc -sv -work rtl_work +incdir+$INC_PATH +incdir+$TINC_PATH $TB_PATH/src/espi_master_bfm.sv
eval vlog +acc -sv -work rtl_work +incdir+$INC_PATH +incdir+$TEST_LIB +define+$SIMULATION_MODE \
    $TB_PATH/src/tb.sv
}

set VSIM_LIBS "\
    -L altera_ver \
    -L lpm_ver \
    -L sgate_ver \
    -L altera_mf_ver \
    -L altera_lnsim_ver \
    -L fiftyfivenm_ver \
    -L rtl_work \
    -L work \
    "

#+nowarnTSCALE 
alias r_rtl {
    eval vsim $VSIM_LIBS +nowarnTSCALE -voptargs="+acc" +alltests tb
run -all
}

alias rc {
    eval vsim -c -L altera_ver -L lpm_ver -L sgate_ver -L altera_mf_ver -L altera_lnsim_ver \
        -L fiftyfivenm_ver -L rtl_work -L work  tb
}

